//  this library.
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/subject/collection_type_enum.dart';
import 'package:hktk_app/model/practice/practice_question_model.dart';

/// 试题集合模型
class QuestionCollectionModel {
  // 集合id
  String? id;

  // 集合名子
  String? name;

  // 最后做题id
  String? lastId;

  // 集合类型
  CollectionTypeEnum? type;

  // 记录集合类型
  CtEnum? recordsType;

  // 试题集合
  List<ContentCollection>? content;

  QuestionCollectionModel({
    this.id,
    this.name,
    this.lastId,
    this.type,
    this.recordsType,
    this.content,
  });

  QuestionCollectionModel.fromJson(Map<String, dynamic> json) {
    id = json["id"];
    name = json["name"];
    lastId = json["lastId"];
    if (json["type"] != null) {
      type = CollectionTypeEnum.getTypeEnum(json["type"]);
    }
    if (json["recordsType"] != null) {
      recordsType = CtEnum.getTypeEnum(json["recordsType"]);
    }
    if (json["content"] != null) {
      content = <ContentCollection>[];
      json["content"].forEach((v) {
        content!.add(ContentCollection.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data["id"] = id;
    data["name"] = name;
    data["lastId"] = lastId;
    if (type != null) {
      data["type"] = type!.name;
    }
    if (recordsType != null) {
      data["recordsType"] = recordsType!.name;
    }
    if (content != null) {
      data["content"] = content!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

// 试题集合
class ContentCollection {
  // 聚合分类名称
  String? tyName;

  // 集合描述
  String? desc;

  // 当前聚会提示总分
  double? score;

  // 聚会排序
  int? sort;

  // 试题列表
  List<PracticeQuestionModel>? qs;

  ContentCollection({
    this.tyName,
    this.desc,
    this.score,
    this.sort,
    this.qs,
  });

  ContentCollection.fromJson(Map<String, dynamic> json) {
    tyName = json["tyName"];
    desc = json["desc"];
    if (json["score"] != null) {
      score = double.parse(json["score"].toString());
    }
    sort = json["sort"];
    if (json["qs"] != null) {
      qs = <PracticeQuestionModel>[];
      json["qs"].forEach((v) {
        qs!.add(PracticeQuestionModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data["tyName"] = tyName;
    data["desc"] = desc;
    data["score"] = score;
    data["sort"] = sort;
    if (qs != null) {
      data["qs"] = qs!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
